package com.zoe.onelink.plugin.check.autoconfigure;

import com.zoe.onelink.enhancer.init.ApplicationInitializer;
import com.zoe.onelink.plugin.check.ApplicationPropertyCheckerComposite;
import com.zoe.onelink.plugin.check.EnvironmentChecker;
import com.zoe.onelink.plugin.check.property.OnelinkCheckerProperties;
import com.zoe.onelink.plugin.check.report.PropertyCheckerConsoleReporter;
import com.zoe.onelink.plugin.check.report.PropertyCheckerReporter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.util.List;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-12-14
 */
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(OnelinkCheckerProperties.class)
@ConditionalOnProperty(prefix = OnelinkCheckerProperties.PREFIX, name = "enabled", matchIfMissing = true)
public class OnelinkCheckerAutoConfiguration {

    @Bean
    public ApplicationInitializer applicationConfigChecker(OnelinkCheckerProperties onelinkCheckerProperties,
                                                           List<EnvironmentChecker> environmentCheckers,
                                                           List<PropertyCheckerReporter> propertyCheckerReporters,
                                                           Environment environment) {
        return new ApplicationPropertyCheckerComposite(onelinkCheckerProperties, environmentCheckers, propertyCheckerReporters, environment);
    }

    @Bean
    public PropertyCheckerReporter defaultPropertyCheckerReporter() {
        return new PropertyCheckerConsoleReporter();
    }

}
